package com.sgcc.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @BelongsProject: springcloud
 * @BelongsPackage: com.sgcc.controller
 * @Author: LiMengshuai
 * @CreateTime: 2019-07-24 10:37
 * @Description: ${Description}
 */
@RestController
public class Controller {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/consumer/hello/{string}")
    @HystrixCommand(fallbackMethod = "error1")
    public String hello(@PathVariable String string){
        if("consumererror".equals(string)){
            throw new RuntimeException("有问题！！！");
        }
        return restTemplate.getForObject("http://service-provider/hello/"+string,String.class);
    }

    public String error1(@PathVariable String string){
        return "consumer:error:"+string;
    }

}
